<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>修改生产大数据</title>
		<link href="__CSS__/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="__CSS__/iconfont.css" />
		<link rel="stylesheet" href="__CSS__/style.css" />
		<link rel="stylesheet" href="__CSS__/mall.css" />
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" id="return"></a>
			<h1 class="mui-title">修改生产大数据</h1>
		</header>
		<div class="mui-content ">
			<div class="gerenzl_nr">
				<form id="myForm" class="mui-input-group gerenzl_group">
					<div class="mui-input-row ">
						<label><em>*</em>产品名称</label>
						<input type="text" name="name" value="{$model.name|default=''}" class="mui-input-group" placeholder="请填写农家乐名">
					</div>
					<div class="mui-input-row ">
						<label style="width: 50%;">建档立卡扶贫户</label>
						<select style="width: 40%;" class="mui-btn mui-btn-block" name="jiandang" >
							<option value="0" {if $model.jiandang=='0' }selected{/if}>否</option>
							<option value="1" {if $model.jiandang=='1' }selected{/if}>是</option>
						</select>
					</div>
					<div class="mui-input-row ">
						<label><em>*</em>产品图</label>
						<div class="actions" style="float: right;">
							<div class="file-btn" style="border: 1px solid #CCCCCC;">
								<input type="hidden" id="thumb" name="thumb" value="{$model.thumb|default=''}">
								<input onchange="UpladFile('product', 500)" type="file" accept="image/*" id="file" name="file" multiple>
								<span><img class='img_list' src="{$model.thumb|default='__IMG__/logo1.png'}" id='thumb_img' style="width: 100%;height: 100%;border-radius: 100%" ></span>
							</div>
						</div>
					</div>
					<div class="mui-input-row">
						<label><em>*</em>一级分类</label>
						<select class="mui-btn mui-btn-block" name="cate_id1" id="cate1">
							{foreach name='cate' item='vo'}
							<option value="{$vo.id}" {if $vo.id==$model.cate_id1}selected{/if}>{$vo.name}</option>
							{/foreach}
						</select>
					</div>
					<div class="mui-input-row">
						<label><em>*</em>二级分类</label>
						<select class="mui-btn mui-btn-block" name="cate_id2" id="cate2">
							{foreach name='cate2' item='vo'}
							<option value="{$vo.id}" {if $vo.id==$model.cate_id2}selected{/if}>{$vo.name}</option>
							{/foreach}
						</select>
					</div>
					<div class="mui-input-row">
						<label><em>*</em>产品品类</label>
						<select class="mui-btn mui-btn-block" name="cate_item" id="cate3">
							{foreach name='cate3' item='vo'}
							<option value="{$vo.id}" {if $vo.id==$model.cate_item}selected{/if}>{$vo.name}</option>
							{/foreach}
						</select>
					</div>
					<div class="mui-input-row">
						<label><em>*</em>产品价格</label>
						<input type="text" name="price" value="{$model.price|default=''}" style="width: 65%;" class="mui-input-group" placeholder="请填写价格描述">
					</div>
					<div class="mui-input-row">
						<label><em>*</em>价格单位</label>
						<select class="mui-btn mui-btn-block" name="unit" id="unit">
							<option value="斤" {if $model.unit=='斤' }selected{/if}>元/斤</option>
							<option value="吨" {if $model.unit=='吨' }selected{/if}>元/吨</option>
							<option value="个" {if $model.unit=='个' }selected{/if}>元/个</option>
							<option value="支" {if $model.unit=='支' }selected{/if}>元/支</option>
							<option value="包" {if $model.unit=='包' }selected{/if}>元/包</option>
							<option value="箱" {if $model.unit=='箱' }selected{/if}>元/箱</option>
							<option value="升" {if $model.unit=='升' }selected{/if}>元/升</option>
							<option value="袋" {if $model.unit=='袋' }selected{/if}>元/袋</option>
							<option value="棵" {if $model.unit=='棵' }selected{/if}>元/棵</option>
							<option value="头" {if $model.unit=='头' }selected{/if}>元/头</option>
							<option value="盒" {if $model.unit=='盒' }selected{/if}>元/盒</option>
							<option value="厅" {if $model.unit=='厅' }selected{/if}>元/厅</option>
							<option value="毫升" {if $model.unit=='毫升' }selected{/if}>元/毫升</option>
							<option value="只" {if $model.unit=='只' }selected{/if}>元/只</option>
							<option value="台" {if $model.unit=='台' }selected{/if}>元/台</option>
							<option value="千克" {if $model.unit=='千克' }selected{/if}>元/千克</option>
							<option value="匹" {if $model.unit=='匹' }selected{/if}>元/匹</option>
							<option value="枚" {if $model.unit=='枚' }selected{/if}>元/枚</option>
							<option value="件" {if $model.unit=='件' }selected{/if}>元/件</option>
							<option value="瓶" {if $model.unit=='瓶' }selected{/if}>元/瓶</option>
							<option value="辆" {if $model.unit=='辆' }selected{/if}>元/辆</option>
							<option value="平方" {if $model.unit=='平方' }selected{/if}>元/平方</option>
							<option value="张" {if $model.unit=='张' }selected{/if}>元/张</option>
						</select>
					</div>
					<div class="hy_line"></div>
					<div class="mui-input-row">
						<label><em>*</em>生产时间</label>
						<input style="width: 45%;margin-top: 15px;" name="produce_time" readonly value="{$model.produce_time|default=date('Y-m-d')}" data-options='{"type":"date","beginYear":1901,"endYear":{:date("Y")}}' class="btns mui-input-group" placeholder="选择生产时间">
					</div>
					<div class="mui-input-row">
						<label><em>*</em>预计销售时间</label>
					</div>
					<div class="mui-input-row">
						<input style="width: 45%;text-align: center;" name="sell_start" readonly value="{$model.sell_start|default=date('Y-m-d')}" data-options='{"type":"date","beginYear":{:date("Y")},"endYear":{:date("Y")+3}}' class="btns mui-input-group" placeholder="选择开始时间"> 到
						<input style="width: 45%;text-align: center;" name="sell_end" readonly value="{$model.sell_end|default=date('Y-m-d')}" data-options='{"type":"date","beginYear":{:date("Y")},"endYear":{:date("Y")+3}}' class="btns mui-input-group" placeholder="选择结束时间">
					</div>
					<div class="mui-input-row">
						<label><em>*</em>每天可供应量</label>
						<input type="text" name="day_total" value="{$model.day_total|default=''}" style="width: 65%;" class="mui-input-group" placeholder="请填写每天可供应量人">
					</div>
					<div class="mui-input-row">
						<label><em>*</em>预计产量</label>
						<input type="text" name="yj_total" value="{$model.yj_total|default=''}" style="width: 65%;" class="mui-input-group" placeholder="请填写预计产量">
					</div>
					<div class="mui-input-row">
						<label><em>*</em>总产量</label>
						<input type="text" name="total" value="{$model.total|default=''}" style="width: 65%;" class="mui-input-group" placeholder="请填写本年度本产品生产总量">
					</div>
					<div class="mui-input-row ">
						<label style="width: 50%;">已有销售途径量</label>
						<input style="width: 40%;" type="text" name="marketing" value="{$model.marketing|default=''}" class="mui-input-group" placeholder="请填写已有销售途径量">
					</div>
					<div class="mui-input-row ">
						<label style="width: 40%;">库存量</label>
						<input style="width: 50%;" type="text" name="stocking" value="{$model.stocking|default=''}" class="mui-input-group" placeholder="请填写现有的库存量">
					</div>
					<div class="hy_line"></div>
					<div class="mui-input-row">
						<label><em>*</em>地区</label>
						<input type="text" readonly="" placeholder="请选择地区" id="myAddrs" data-key="{$model.area|default=''}" value="">
						<input type="hidden" id="area" name="area" value="{$model.area|default=''}" />
					</div>
					<div class="mui-input-row">
						<label>详细地址</label>
						<input type="text" name="address" value="{$model.address|default=''}" class="mui-input-group" placeholder="请填写详细地址">
					</div>
					<div class="mui-input-row">
						<label>详细图片</label>
						<div class="ordpj_imgbox">
							<div id="img_list" class="img_list">
								{foreach name="$model.thumbs" item="vo"}
								<div style="display: block;float: left;margin-right: 5px;">
									<input value="{$vo}" type="hidden" name="thumbs[]" />
									<img src="{$vo}" style="width: 100px;height: 100px;" /><br>
									<a onclick="imgdel(this)">删除</a>
								</div>
								{/foreach}
							</div>
						</div>
						<div class="mui-input-row">
							<button class="file-btn">
				                <span><i class="mui-icon mui-icon-camera fa"></i></span>
				                <input onchange="UpladFiles('farmstay', 900)" type="file" accept="image/*" id="files" name="files" multiple>
				            </button>
						</div>
						<div class="mui-input-row">
							<label>备注</label>
							<textarea name="content" style="width:100%;height:150px;border: 1px solid #CCCCCC;">{$model.content|default=''}</textarea>
						</div>
						<input type="hidden" name="id" value="{$model.id}" />
						<button type="submit" class="fjysq_sbtn">保存</button>
					</div>
				</form>
			</div>
		</div>
	</body>

</html>
<script src="__JS__/jquery.min.js"></script>
<script src="__JS__/jquery.validate.min.js"></script>
<script src="__JS__/mui.min.js"></script>
<script src="__LIB__/layer.js"></script>
<script src="__JS__/image.zip.js"></script>
<script src="__JS__/index.js"></script>
<!-- 时间选择器-->
<link rel="stylesheet" type="text/css" href="__JS__/mui.picker.min.css" />
<script src="__JS__/mui.picker.min.js"></script>
<!-- end 时间选择器-->
<link href="__JS__/scs.min.css" rel="stylesheet">
<script src="__JS__/jquery.scs.min.js"></script>
<script src="__JS__/district.js"></script>
<script>
	$("#return").click(function() {
		location.href = "{:url('member/product')}";
	});
	(function($) {
		$.init();
		var btns = $('.btns');
		btns.each(function(i, btn) {
			btn.addEventListener('tap', function() {
				var _self = this;
				if(_self.picker) {
					_self.picker.show(function(rs) {
						_self.value = rs.text;
						_self.picker.dispose();
						_self.picker = null;
					});
				} else {
					var optionsJson = this.getAttribute('data-options') || '{}';
					var options = JSON.parse(optionsJson);
					var id = this.getAttribute('id');
					_self.picker = new $.DtPicker(options);
					_self.picker.show(function(rs) {
						_self.value = rs.text;
						_self.picker.dispose();
						_self.picker = null;
					});
				}
			}, false);
		});
	})(mui);
	$(function() {

		// 二级联动
		$("#cate1").change(function() {
			var pid = $(this).val();
			$.ajax({
				type: "post",
				url: "{:url('member/product_cates')}",
				data: {
					pid: pid
				},
				success: function(json) {
					if(json.code == 1) {
						str = '';
						for(var i = 0; i < json.data.length; i++) {
							str += '<option value="' + json.data[i].id + '">' + json.data[i].name + '</option>';
						}
						$("#cate2").html(str);
						$("#cate2").change();
					} else {
						layer.msg(json.msg);
					}
				}
			});
		});

		// 三级联动
		$("#cate2").change(function() {
			var pid = $(this).val();
			console.log(pid);
			$.ajax({
				type: "post",
				url: "{:url('member/product_items')}",
				data: {
					pid: pid
				},
				success: function(json) {
					$("#cate3").html("");
					if(json.code == 1) {
						str = '';
						for(var i = 0; i < json.data.length; i++) {
							str += '<option value="' + json.data[i].id + '">' + json.data[i].name + '</option>';
						}
						$("#cate3").html(str);
					} else {
						layer.msg(json.msg);
					}
				}
			});
		});
		$("#myForm").validate({
			focusInvalid: true,
			onkeyup: false,
			ignore: "",
			onfocusout: false,
			showErrors: function(errorMap, errorList) {
				var msg = "";
				if(errorList != null && errorList != "") {
					msg = errorList[0]['message'];
					layer.msg(msg);
				}
			},
			submitHandler: function(form) { //表单提交句柄,为一回调函数，带一个参数：form   
				app.ajax(window.location.href, true);
			},
			rules: {
				name: {
					required: true
				},
				price: {
					required: true
				},
				unit: {
					required: true
				},
				area: {
					required: true
				},
				produce_time: {
					required: true
				},
				day_total: {
					required: true
				},
				yj_total: {
					required: true
				},
				total: {
					required: true
				}
			},
			messages: {
				name: {
					required: "请填写产品名称"
				},
				price: {
					required: "请填写产品价格"
				},
				unit: {
					required: "请选择单位"
				},
				area: {
					required: "请选择地区"
				},
				produce_time: {
					required: "请选择生产时间",
				},
				day_total: {
					required: "请填写每天可供应量",
				},
				yj_total: {
					required: "请填写预计产量",
				},
				total: {
					required: "请填写总产量",
				}
			}
		});
	});
</script>